package net.scdx.hotel.controller;

import net.scdx.hotel.entity.Room;
import net.scdx.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    /**
     * query rooms by hotel id
     */
    @GetMapping("/query_rooms_by_hotel_id")
    public Map<String,Object> queryRoomsByHotelId(Integer hotelId) {
        Map<String,Object> modelMap = new HashMap<>();

        try {
            List<Room> rooms = roomService.queryRoomsByHotelId(hotelId);

            if (rooms == null)
                rooms = new ArrayList<Room>();

            modelMap.put("success", true);
            modelMap.put("count", rooms.size());
            modelMap.put("data", rooms);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return modelMap;
    }

}
